<!doctype html>
<html class="x-admin-sm">

<head>
  <meta charset="UTF-8">
  <title>后台登录-X-admin2.2</title>
  <meta name="renderer" content="webkit|ie-comp|ie-stand">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport"
    content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <link rel="stylesheet" href="./css/font.css">
  <link rel="stylesheet" href="./css/login.css">
  <link rel="stylesheet" href="./css/xadmin.css">
  <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
  <script src="./lib/layui/layui.js" charset="utf-8"></script>
</head>

<body class="login-bg">
  <div class="login layui-anim layui-anim-up">
    <div class="message">澡堂-管理登录</div>
    <div id="darkbannerwrap"></div>
    <form method="post" class="layui-form">
      <input name="username" placeholder="用户名" type="text" lay-verify="required" class="layui-input">
      <hr class="hr15">
      <input name="password" lay-verify="required" placeholder="密码" type="password" class="layui-input">
      <hr class="hr15">
      <div class="layui-form-item">
        <div class="layui-row inline-block" style="display: flex;align-items: center;justify-content: center;">
          <div class="layui-col-xs7">
            <input name="code" type="text" lay-verify="required" placeholder="验证码" class="layui-input">
          </div>
          <div class="layui-col-xs5" style="display: flex;justify-content: center;">
            <img class="login-captcha" src="http://127.0.0.1:3000/lib/svg">
          </div>
        </div>
      </div>
      <input value="登录" lay-submit lay-filter="login" style="width:100%;" type="submit">
      <hr class="hr20">
    </form>
  </div>

  <script>
    $(function () {
      layui.use('form', function () {
        var form = layui.form;
        var $ = layui.jquery;
        form.on('submit(login)', function (data) {
          layer.load(2);
          $.ajax({
            url: '/isAdminLogin',
            data: data.field,
            type: 'post',
            dataType: 'JSON',
            success: function (data) {
              if (data.code) {
                console.log(data.data)
                layui.sessionData('admin', {
                  key: 'info',
                  value: data.data
                });
                layer.msg('登录成功', { icon: 1 }, function () {
                  location.replace('./index.html');
                });
              } else {
                layer.closeAll('loading');
                layer.msg(data.data, { icon: 5 });
                $('.layui-form-item input').val('');
              }
            },
            error: function (xhr) {
              layer.closeAll('loading');
              if (xhr.status == 400) {
                layer.msg('账号或密码错误', { icon: 5 });
                $('.layui-form-item input').val('');
              }
            },
            complete: function () {
              let capt = $('.login-captcha')[0];
              capt.src = capt.src + '?t=' + (new Date).getTime();
            }
          });
          return false;
        });
        $('.login-captcha').click(function () {
          this.src = this.src + '?t=' + (new Date).getTime();
        });
      });
    })
  </script>
</body>

</html>